﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Entity;
using ClassLibrary.DAO;

public partial class UserControl_ucComment : System.Web.UI.UserControl
{
    TblContentCommentDAO commentDAO = new TblContentCommentDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = Request.QueryString["id"];
            if (id == null || id == "")
                Response.Redirect("~/Products.aspx");

            //  lb_email.Visible = false;
            if (id != null)
            {
                loadComment();

            }
            if (Session[Global.SESSION_LOGGED_USER] != null)
            {
                lb_email.Visible = true;
                lb_email.Text = ((TblUserAccount)Session[Global.SESSION_LOGGED_USER]).Email;

            }
            else
            {

            }
        }

    }
    private void loadComment()
    {
        string id = Request.QueryString["id"];
        recomment.DataSource = commentDAO.GetComment(Global.ConvertToInt(id));
        recomment.DataBind();
    }
    protected void btbinhluan_Click(object sender, EventArgs e)
    {

        if (Session[Global.SESSION_LOGGED_USER] != null)
        {
            try
            {
                TblComment comment = new TblComment();
                comment.AccountID = ((TblUserAccount)Session[Global.SESSION_LOGGED_USER]).AccountID;
                comment.DateComment = Convert.ToDateTime(DateTime.Now);
                comment.ContentComment = txtnoidung.Text;
                comment.ItemID = Global.ConvertToInt(Request.QueryString["id"]);

                commentDAO.Insert(comment);
                loadComment();
                txtnoidung.Text = string.Empty;
            }

            catch (Exception ex)
            {
                Session[Global.SESSION_ERROR] = ex;
                Response.Redirect(Global.ERROR_PAGE, true);
            }
        }
        else
            Response.Redirect("Default.aspx");

    }
}
